package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.ComplaintMapper;
import com.jianglin.model.Complaint;
import com.jianglin.service.IComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ComplaintServiceImpl implements IComplaintService {

    @Autowired
    private ComplaintMapper complaintMapper;

    @Override
    public PageInfo<Complaint> findComplaintAll(int page, int pagesize, Complaint complaint) {
        PageHelper.startPage(page, pagesize);
        List<Complaint> list = complaintMapper.queryComplaintAll(complaint);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Complaint> findListByPage(Integer page, Integer pageCount) {
        PageHelper.startPage(page, pageCount);
        List<Complaint> list = complaintMapper.selectAll();
        return new PageInfo<>(list);
    }

    @Override
    public int add(Complaint complaint) {
        return complaintMapper.insert(complaint);
    }

    @Override
    @Transactional
    public int delete(Long id) {
        return complaintMapper.deleteById(id);
    }

    @Override
    public int updateData(Complaint complaint) {
        return complaintMapper.update(complaint);
    }

    @Override
    public Complaint findById(Long id) {
        return complaintMapper.findById(id);
    }}
